package com.itheima.consumer.listeners;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class MqListener {

    @Autowired
    RabbitTemplate  rabbitTemplate;

    @RabbitListener(queues = "simple.queue")
    public void listener(String msg) {
        System.out.println("simple.queue接收到消息：" + msg);
    }

    @RabbitListener(queues = "fanout.queue1")
    public void listenerFanoutQueue1(String msg) {
        System.out.println("fanout.queue1接收到消息：" + msg);
    }

    @RabbitListener(queues = "fanout.queue2")
    public void listenerFanoutQueue2(String msg) {
        System.out.println("fanout.queue2接收到消息：" + msg);
    }

    @RabbitListener(queues = "direct.queue1")
    public void listenerDirectQueue1(String msg) {
        System.out.println("direct.queue1接收到消息：" + msg);
    }
    @RabbitListener(queues = "direct.queue2")
    public void listenerDirectQueue2(String msg) {
        System.out.println("direct.queue2接收到消息：" + msg);
    }

    // Topic路由监听器
    @RabbitListener(queues = "topic.queue1")
    public void listenerTopicQueue1(String msg) {
        System.out.println("topic.queue1接收到消息（匹配order.*）：" + msg);
    }

    @RabbitListener(queues = "topic.queue2")
    public void listenerTopicQueue2(String msg) {
        System.out.println("topic.queue2接收到消息（匹配*.create）：" + msg);
    }

    @RabbitListener(queues = "topic.queue3")
    public void listenerTopicQueue3(String msg) {
        System.out.println("topic.queue3接收到消息（匹配order.#）：" + msg);
    }
}
